#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll rr() {
    ll s = 0, w = false, c = getchar();
    for (; !isdigit(c); c = getchar())
        w = w || c == '-';
    for (; isdigit(c); c = getchar())
        s = s * 10 + c - '0';
    return w ? -s : s;
}

// END OF HEADER

int main() {
    int n = rr();
    int sum = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        int vi = rr();
        sum += vi;
        ans = max(ans, sum);
        sum = max(sum, 0);
    }
    printf("%d\n", ans);
    return 0;
}
